package com.picshare.util;

import org.springframework.stereotype.Component;

@Component
public class FileUtil {
    
    public String formatFileSize(long bytes) {
        if (bytes == 0) return "0 Bytes";
        String[] sizes = new String[]{"Bytes", "KB", "MB", "GB"};
        int i = (int) (Math.log(bytes) / Math.log(1024));
        return Math.round(bytes / Math.pow(1024, i) * 100.0) / 100.0 + " " + sizes[i];
    }
}